class CirclePost {
    constructor(obj) {
        this.requestTime = obj.time;
        this.title = obj.body.title;
        this.publishTime = obj.body.publishTime;
        this.content = obj.body.content;
        this.circlePostTypeId = obj.body.circlePostTypeId;
    }

    check() {
        let { title, content, publishTime, circlePostTypeId, requestTime } = this;
        // 标题和内容判空
        if (!title || !content) {
            return { success: false, err: '标题和内容不允许为空' };
        }
        // 判断 标题、内容 去除空白字符之后是否为空内容
        let format_circleTitle = title.replace(/\s+/g, '');
        let format_circleContent = content.replace(/\s+/g, '');
        if (!format_circleTitle || !format_circleContent) {
            return { success: false, err: '标题和内容不允许为空' };
        }
        // 时间判空
        if (!publishTime) {
            return { success: false, err: '时间为空' };
        }
        // 验证时间的正确性
        let publishTimeObj;
        try {
            publishTimeObj = new Date(publishTime);
        } catch (err) {
            return { success: false, err: '时间格式错误' };
        }
        // 时间节点验证
        if (publishTimeObj > requestTime) {
            return { success: false, err: '时间节点错误' };
        }
        // 超时验证
        if (new Date(publishTimeObj.getTime() + 5 * 60 * 1000) < requestTime) {
            return { success: false, err: '超时5分钟' };
        }
        // 动态类型可以为空
        circlePostTypeId = circlePostTypeId || null;
        return { success: true };
    }
}

module.exports = CirclePost;